import {PluginCommand} from "./PluginCommand";

class ElectricalCommand extends PluginCommand {
    /**
     * 构造函数
     */
    constructor() {
        super();
    }

    /**
     * 导入解析
     */
    importProperty(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.importElectricalProperty(params).then(res => {
                cb(res);
            })
        }
    }

    /**
     * 拾取装配下的实例
     */
    pickInstance(cb) {
        if (this.event) {
            this.event.subscribeInstancePickEvent(res => (
                cb(res.instance)
            ));
        }
    }

    // getInstancePrototypeByInstanceId(params, cb) {
    //     if (this.toolQuery) {
    //         this.toolQuery.getInstanceProtoRefByInstanceId(params).then(res => {
    //             cb(res?.data?.instance);
    //         })
    //     }
    // }

    getElectricalPropertyXML(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.getElectricalPropertyXML(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb(undefined);
                }
            })
        }
    }

    clearAllSelectedInstances() {
        if (this.toolQuery) {
            this.toolQuery.clearAllSelectedInstances();
        }
    }

    getCatiaInstallType(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.getCatiaInstallType(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb('');
                }
            })
        }
    }

    batchDealSelectedNodes(params,cb){
        if (this.toolQuery) {
            this.toolQuery.batchDealSelectedNodes(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb('');
                }
            })
        }
    }

    getInstanceTree(cb) {
        if (this.query) {
            this.query.getInstanceTree().then(res => {
                cb(res?.data?.instanceTree);
            });
        }
    }

    getAttributesByInstanceNode(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.getAttributesByInstanceNode(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb(undefined);
                }
            })
        }
    }
    updateElectricalAttributeById(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.updateElectricalAttributeById(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb(false);
                }
            })
        }
    }

    deleteElectricalAttributeById(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.deleteElectricalAttributeById(params).then(res => {
                if (res?.code === 200) {
                    cb(res?.data);
                } else {
                    cb(false);
                }
            })
        }
    }

    insertElectricalAttributeData(params,cb){
        if (this.toolQuery) {
            this.toolQuery.insertElectricalAttributeData(params).then(res => {
                if (res?.code === 200) {
                    cb('OK');
                } else {
                    cb(undefined);
                }
            })
        }
    }

    saveElectricalAttributeData(params, cb) {
        if (this.toolQuery) {
            this.toolQuery.saveElectricalAttributeData(params, this.commandId).then(res => {
                cb(res);
            })
        }
    }

    setInstanceVisible(params){
        if (this.toolQuery) {
            this.toolQuery.setInstanceVisible(params);
        }
    }

    // leakageItemsCheck(params, cb) {
    //     if (this.toolQuery) {
    //         this.toolQuery.leakageItemsCheck(params).then(res => {
    //             cb(res?.data);
    //         })
    //     }
    // }

    async getCurrentAssemblyFlattenTree() {
        if (this.toolQuery) {
            let res = await this.toolQuery.getCurrentAssemblyFlattenTree();
            return res?.data?.data;
        }
    }

    setInstanceInvisible(params){
        if (this.toolQuery) {
            this.toolQuery.setInstanceInvisible(params);
        }
    }

    // getCurrentAssemblyStructure(cb) {
    //     if (this.toolQuery) {
    //         this.toolQuery.getCurrentAssemblyStructure().then(data => {
    //             debugger
    //             cb(data);
    //         })
    //     }
    // }

    // getCurrentAssemblyCompsAttributes(params, cb) {
    //     if (this.toolQuery) {
    //         this.toolQuery.getCurrentAssemblyCompsAttributes(params).then(data => {
    //             cb(data);
    //         })
    //     }
    // }

    //拾取左侧装配树的实例，或，拾取模型UI上的实例---此方法找的是装配assembly
    pickAssemblyInstances(cb) {
        if (this.event) {
            this.event.subscribeAssemblyInstancesPickEvent(res => {
                    cb(res.instance);
            });
        }
    }

    //支持同时拾取装配和实例
    pickAssemblyAndPartInstances(cb){
        if(this.event){
            this.event.subscribeAllInstancesPickEvent(res=>{
                cb(res.instance);
            })
        }
    }

     async getInsChildren(instanceIdArr) {
         if (this.toolQuery) {
             let res = await this.toolQuery.getInsChildrenIds(instanceIdArr);
             if(res?.code===200 && res?.data?.children.length>0){
                 return res?.data?.children;
             }else {
                 return [];
             }

         }
     }
}

const InstallTypeEnum = {
    ConnectorFasteningPart:'连接器',
    GroundingPart:'接地桩',
    ProtectionMaterialForHoleEdging:'防磨边/圈',
    WireSupportingPart:'线缆支撑件',
    SPAClampPart:'双卡箍限位器',
    ClampPart:'金属卡箍',
    SealingFittingPart:'密封穿墙件',
    RelaySocketPart:'快卸式继电器座',
    TerminalBoardPart:'接线板',
    ElectricalHarnessSeparator:'电气线束隔离件',
    AdhesiveHarnessMountPart:'粘接型线束安装件',
    ModuleRailPart:'模块导轨',
    WireHarnessStiffenerTubePart:'线束加强杆',
    MountPart:'安装座',
    InLineSpliceRectangleConnectorHousingPart:'在线连接矩形电连接器壳体',
    OtherPart:'未识别零件',
}

const electricalCommand = new ElectricalCommand();
export {electricalCommand,InstallTypeEnum};